package com.job2e.common;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Random;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONSerializer;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.code.jbauble.mvc.Controller;
import com.google.code.jbauble.mvc.Result;
import com.google.code.jbauble.mvc.support.UrlTool;
import com.job2e.common.utils.CommonUtil;

public abstract class BaseController extends Controller {
	protected static final int PAGE_MAX_SIZE = 20;
	protected UrlTool urlTools = new UrlTool();
	
	protected Result json(Object t) {
		if (t == null)
			throw new IllegalArgumentException();
		
		return output(JSONSerializer.toJSON(t).toString());
	}
	
	protected Integer getPage(HttpServletRequest request) {
		String pageParam = request.getParameter("page");
		if(pageParam == null){
			return 0;
		}
		Integer page = Integer.parseInt(pageParam);
		return page == null? 0 : page;
	}
	
	protected String getUrl(String url) {
		return urlTools.get(url);
	}
}
